//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<key_map.h>
///	@path	~/src/gui/input/
///	@date	2007/12/11
///	@desc	Key input mapping.

#pragma once

#include "xeres.h"

#include <map>

#include "lib/utilities/callback.h"

#include "gui/input/input.h"

#include "appear/app/input_handler.h"

namespace xeres {

	/*!
		\class	KeyMap
		\brief	Key input mapping, can be used as hot key mapper or key accelerator.
				This key map is not designed for complicate keying behavior,
				it should be used in simple way of key input, such as in editor.
				To achieve complicate input behavior, a game logic written in script is recommended.
	*/
	class KeyMap : public InputHandler
	{
	public:

		/// \ctor
		KeyMap( void );

		/// \dtor
		virtual ~KeyMap( void );

	public:
	//@ interface

		/*!
			\brief		Process key input message.
		*/
		virtual HandleInput OnKeyInput( const KeyInput& input );

		/*!
			\brief		Process mouse input message.
		*/
		virtual HandleInput OnMouseInput( const MouseInput& input );

	//@ local

		/*!
			\brief		Set 1 or 2 keys of mapping.
						Notice keys that would affect status cannot be action key.
						'call' will be execute at key pressing input.
		*/
		bool SetKey( uint32 status , KeyInput::Key action_key ,
			function<void(void)> call , bool override = false );

		/*!
			\brief		Clear all key mapping.
		*/
		void ClearAll( void );

	private:

		// internal structure to note down key event calls
		struct _KeyNote
		{
			uint32					m_status;
			KeyInput::Key			m_key;
			function<void(void)>	m_call;
		};

		// find key
		_KeyNote * FindKey( uint32 status , KeyInput::Key action_key );

	//@ data

		typedef std::multimap<KeyInput::Key,_KeyNote> _KeyMap;

		_KeyMap		m_keynotes;

	};

} // namespace xeres
